package com.example.blood_sugar.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.blood_sugar.fragments.BloodSugarFragment30days;
import com.example.blood_sugar.fragments.BloodSugarFragment7days;
import com.example.blood_sugar.fragments.BloodSugarFragmentTotal;

import java.util.List;

/**
 * 血糖表格中未TabLayout适配fragment的适配器
 */
public class BloodSugarFragmentAdapter extends FragmentPagerAdapter {

    private List<String> list;

    public BloodSugarFragmentAdapter(FragmentManager fm, List<String> list) {
        super(fm);
        this.list = list;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 2)
            return BloodSugarFragmentTotal.newInstance(list.get(position));
        if (position == 1)
            return BloodSugarFragment30days.newInstance(list.get(position));
        return BloodSugarFragment7days.newInstance(list.get(position));
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return list.get(position);
    }
}